//
// Created by 45595 on 2022-02-20.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> inOrder,postOrder,result[35];

void solution(int inL,int inR,int postL,int postR,int level){
    if(inL>inR) return;
    result[level].push_back(postOrder[postR]);

    int i=0;
    while(inOrder[i]!=postOrder[postR]) i++;
    solution(inL,i-1,postL,postL+i-inL-1,level+1);
    solution(i+1,inR,postL+i-inL,postR-1,level+1);
}

int main() {
    freopen("../A1127.txt", "r", stdin);
    int N;
    cin>>N;

    inOrder.resize(N);
    for(int i=0;i<N;i++) cin>>inOrder[i];
    postOrder.resize(N);
    for(int i=0;i<N;i++) cin>>postOrder[i];

    solution(0,N-1,0,N-1,0);
    for(int i=0;i<N;i++){
        if(result[i].size()==0) return 0;
        if(i%2==1){
            for(int j=0;j< result[i].size();j++) {
                cout<<" "<<result[i][j];
            }
        }else{
            for(int j=result[i].size()-1;j>=0;j--) cout<<" "<<result[i][j];
        }
    }
    return 0;
}